directory index of "/usr/share/nginx/html/" is forbidden 您所在的位置:网站首页 mac 10157 下载 directory index of "/usr/share/nginx/html/" is forbidden

directory index of "/usr/share/nginx/html/" is forbidden

2023-08-27 13:36| 来源: 网络整理| 查看: 265

安装完nginx之后访问本机ip,结果直接报错,然后去查看nginx错误日志,看到如下错误信息,意思是html下面没有 directory index of "/usr/share/nginx/html/" is forbidden 1、如果在/usr/share/nginx/html下面没有index.php,index.html的时候,直接访问域名,找不到文件,会报403 forbidden。

解决办法:直接输入以下命令:

#删除index.html文件 rm /usr/share/nginx/html/index.html #在html目录下面新建一个index.php文件,内容是`` 查看phpinfo echo "" >> /usr/share/nginx/html/index.php 2、还有一个原因就是你的默认的nginx配置文件的location没有指定root路径,我的就是这个问题。

这个就直接在默认的server上面加上:

location / { root html; index index.php index.html index.htm; } 3、如果还是不能正常访问,那就进到nginx的默认配置文件里去找一下,看看有没有如下代码: location ~* \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } 上面代码的意思是把php文件交给php-fpm处理,php-fpm占用的端口号是9000。

配置完以后,记得重启nginx,或者reload一下:

重启nginx:

nginx -s stop nginx

或者:

nginx -s reopen

下面是重新加载nginx的配置文件(推荐这种方式):

service nginx reload

找到nginx的安装目录:

[root@localhost nginx]# which nginx /usr/sbin/nginx #这个是yum安装后默认所在位置

查看nginx的命令提示:

[root@localhost nginx]# nginx -h nginx version: nginx/1.10.2 Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -T : test configuration, dump it and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/share/nginx/) -c filename : set configuration file (default: /etc/nginx/nginx.conf) -g directives : set global directives out of configuration file


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有